package com.cq.oa.web.sm.action;

import oa.base.session.SessionManger;
import oa.base.util.Constants;
import oa.base.util.Page;
import oa.base.web.Action.BaseAction;

import com.cq.oa.domain.sm.Role;
import com.cq.oa.service.sm.RoleService;
import com.cq.oa.utils.StringliptUtil;

public class SmRoleAction extends BaseAction<Role>{

	/**
	 * 
	 */
	private static final long serialVersionUID = 2283944864146115800L;
	
	private RoleService roleService;
	
	private String userIds;
	
	private String userNames;
	
	private Long roleId;
	
	private String roleName;
	
	private String resIds;
	
	private String resNames;
	
	
	

	public String getResIds() {
		return resIds;
	}


	public void setResIds(String resIds) {
		this.resIds = resIds;
	}


	public String getResNames() {
		return resNames;
	}


	public void setResNames(String resNames) {
		this.resNames = resNames;
	}


	public String getUserIds() {
		return userIds;
	}


	public void setUserIds(String userIds) {
		this.userIds = userIds;
	}


	public String getUserNames() {
		return userNames;
	}


	public void setUserNames(String userNames) {
		this.userNames = userNames;
	}


	public Long getRoleId() {
		return roleId;
	}


	public void setRoleId(Long roleId) {
		this.roleId = roleId;
	}


	public String getRoleName() {
		return roleName;
	}


	public void setRoleName(String roleName) {
		this.roleName = roleName;
	}


	public void setRoleService(RoleService roleService) {
		this.roleService = roleService;
	}


	@Override
	protected Class<Role> getEntityClass() {
		return Role.class;
	}
	
	public String findByPage() throws Exception {
		filterMap.put("orgSid", SessionManger.getOrgId());
		filterMap.put(Constants.WHERE_LIKE+"cname", entity.getCname());
		shortMap.put(Constants.ORDER_BY_ASC, "orderBy");
		Page<Role> users = roleService.findByPage(filterMap, linkMap,shortMap, super.getPageNo(),
				super.getPageSize());
		this.renderJsonSuccess(jsonUtils.getExtJson(users, new String[] {}));
		return JSON;
	}
	public String operate(){
		if(null!=entity.getSid()){
			entity = roleService.findByParmkeys(entity.getSid());
		}
		return "operate";
	}
	
	public String save(){
		if(null!=entity.getSid()){
			this.roleService.update(entity);
		}else{
			this.roleService.create(entity);
		}
		this.renderJsonSuccess();
		return JSON;
	}
	
	public String delete(){
		this.roleService.delete(entity.getSid());
		this.renderJsonSuccess();
		return JSON;
	}
	/**
	 * 管理用户
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String relationUser(){
		//List<UserRole> users = this.roleService.findUserRoleById(roleId);
		return "relationUser";
	}
	/**
	 * 管理资源
	 * @return
	 * lilang 
	 * 2013-10-11下午1:03:34
	 */
	public String relationRes(){
		return "relationRes";
	}
	/**
	 * 保存关联人员
	 * @return
	 * lilang 
	 * 2013-10-11下午1:04:39
	 */
	public String saveRelationUser(){
		try{
			this.roleService.doRoleUnUser(roleId, roleName, StringliptUtil.splitString(userIds), StringliptUtil.split(userNames));
			this.renderJsonSuccess();
		}catch(Exception e){
			this.renderJsonError(e);
		}
		return JSON;
	}
	/**
	 * 保存关联资源
	 * @return
	 * lilang 
	 * 2013-10-11下午1:04:39
	 */
	public String saveRelationRes(){
		try{
			this.roleService.doRoleUnRes(roleId, roleName, StringliptUtil.splitString(resIds), StringliptUtil.split(resNames));
			this.renderJsonSuccess();
		}catch(Exception e){
			this.renderJsonError(e);
		}
		return JSON;
	}
	
}
